<?php
namespace app\admin\model;

use think\Model;

class ClientUsers extends Model{

    protected $table = 'users';
    protected $pk = 'id';

    public static $user_status = ['禁止使用', '正常使用'];
    public static $user_verification = ['未核销', '已核销'];
    public static $user_note = ['不通知', '通知'];

    public function getBirthdayStrAttr($val, $data){
        return date('Y-m-d', $data['birthday']);
    }

    public function getSexStrAttr($val, $data){
        $return = ['男', '女'];
        return $return[$data['sex']];
    }

    public function getIsVerificationStrAttr($val, $data){
        $str = self::$user_verification[$data['is_verification']];
        if($data['is_verification']){
            $str .= ' (于'.date('Y-m-d H:i:s', $data['verification_time']).')';
        }
        return $str;
    }

    public function getStatusStrAttr($val, $data){
        return self::$user_status[$data['status']];
    }

    public function getFirstWeightStrAttr($val, $data){
        $msg = $data['first_weight']>0 ? $data['first_weight'] : '未称重';
        return $msg;
    }

    public function getLastWeightStrAttr($val, $data){
        $msg = $data['last_weight']>0 ? $data['last_weight'] : '未称重';
        return $msg;
    }

    public function getNoteStrAttr($val, $data){
        return self::$user_note[$data['note']];
    }

    public function getPIdStrAttr($val, $data){
        $res = $this->where('id', $data['p_id'])->field('id, nickname')->find();
        if(!$res){
            $res['id'] = 0;
            $res['nickname'] = '无推荐';
        }
        return $res;
    }

}